package es.albarregas.ajax;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import es.albarregas.modelo.Cliente;
import es.albarregas.modelo.ModelFacade;
import es.albarregas.pojo.Categoria;
import es.albarregas.pojo.Coleccion;
import es.albarregas.pojo.Pedido;


public class ComprobarExisteYaEmailCliente extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public ComprobarExisteYaEmailCliente() {
		super();
		// TODO Auto-generated constructor stub
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		String email = request.getParameter("email");
		String respuestaHTML="NO";
		
		 Collection<Cliente> listaClientes = ModelFacade.getCliente(" WHERE email='"+email+"'");

		 for (Cliente cliente : listaClientes) {
		      respuestaHTML="SI";
		      break;
		}

		PrintWriter out = response.getWriter();
		try {
			out.print(respuestaHTML);
		} finally {
			out.close();
		}

	}

}
